package org.sanm.domain.company;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import org.sanm.common.Result;
import org.sanm.domain.goods.Goods;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> implements CompanyService{
    @Override
    public Company getDetail(Integer id) {
        Company company = getById(id);

        return company;
    }

    @Override
    public List<Company> getByIds(List<Integer> ids) {
        List<Company> list = lambdaQuery().in(Company::getId, ids).list();



        return list;
    }

    @Override
    public Page<Company> page(Integer pageNum, Integer pageSize, String name, String provinceCode, String cityCode, String areaCode, String startDate, String endDate) {

        Page<Company> page = Page.of(pageNum, pageSize);
        lambdaQuery()
                .like(name!= null, Company::getName, name)
                .eq(provinceCode != null, Company::getProvinceCode, provinceCode)
                .eq(cityCode!= null, Company::getCityCode, cityCode)
                .eq(areaCode != null, Company::getAreaCode, areaCode)
                .between(startDate != null, Company::getCreateTime, startDate, endDate)
                .orderByDesc(Company::getCreateTime)
                .page(page);



        return page;
    }
}
